package 并发编程08;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author idea
 * @data 2019/1/23
 */
public class AtomicTest {

    private static AtomicStampedReference<Integer> atomicStampedReference = new AtomicStampedReference<>(1, 0);

    public static void main(String[] args) {

        //第一个参数是指期待读取的时候相应的值是多少
        /**
         * 原理是采用了unsafe包里面的cas操作来直接针对相应对象进行修改
         */
        atomicStampedReference.compareAndSet(100, 2, atomicStampedReference.getStamp(), atomicStampedReference.getStamp() + 1);
        System.out.println(atomicStampedReference.getReference());
    }
}
